#decoding:utf-8
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time
import cv2

browser = webdriver.Firefox() # Get local session of firefox
browser.get("http://www.baidu.com") # Load page
assert u"百度" in browser.title
elem = browser.find_element_by_id("kw") # Find the query box
elem.send_keys("girl" + Keys.RETURN)
time.sleep(1) # Let the page load, will be added to the API
try:
    browser.find_element_by_xpath("//h3/a[contains(text(),'_')]") #find baike in result page
    browser.save_screenshot('D:/source.jpg') #save page 
except NoSuchElementException:
    assert 0, "can't find opencv2 element"
browser.close()

  
winName = 'display image' #窗口名称  
imagePath = 'D:/source.jpg' #图片文件路径  
cv2.namedWindow(winName,cv2.WINDOW_AUTOSIZE) #创建显示窗口  
image=cv2.imread(imagePath) #读取图片  
cv2.imshow(winName, image) #显示图片  
cv2.waitKey(0) #等待，按Esc键退出窗口  
cv2.destroyWindow(winName) #销毁窗口 